unit uAutoUpdate;

interface

uses
  Types, Windows;

const
	UPDATE_CHECK	  = 1;
	UPDATE_BEGINDWON= 2;
  UPDATE_Downfile = 3;
  UPDATE_OK = 4;
  E_OK = 1;
  E_PLIST = 2;
  E_DownFile = 3;

type
  TPatchResult = (PR_OK = 0, PR_PlistNotFound, PR_ERROR);
  TFNCallback = procedure(EventType: Integer; dwParam1, dwParam2, dwParam3, dwParam4: DWord; szData: PChar); stdcall;
  PUpdateInfo = ^TUpdateInfo;
  TUpdateInfo = record
    Url:array[0..MAX_PATH-1] of char;
    callBack:TFNCallback;
  end;
{$IFDEF DLL}
function GetVersion: Integer; stdcall;
function StartUpdateFiles(info: PUpdateInfo): boolean; stdcall;
function GetNetSpeed: Integer; stdcall;
procedure StopUpdateFiles; stdcall;
procedure ApplyPatch(patchDir: PChar; plist: PChar; ErrorID:PInteger; ErrMsg: PChar); stdcall;
procedure SetOption(option: PChar; value: PChar); stdcall;
implementation
uses
  uMainForm;

function GetVersion: Integer;
begin
  Result := 20110216;
end;

function StartUpdateFiles(info: PUpdateInfo): boolean;
begin
  result := MainForm.StartUpdateFiles(info);
end;

function GetNetSpeed: Integer;
begin
  result := MainForm.GetNetSpeed;
end;

procedure StopUpdateFiles;
begin
  MainForm.StopUpdateFiles;
end;

procedure ApplyPatch(patchDir: PChar; plist: PChar; ErrorID:PInteger; ErrMsg: PChar);
var
  EID: Integer;
  EMsg: string;
begin
  EMsg := '';
  MainForm.ApplyPatch(patchDir, plist, EID, EMsg);
  ErrorID^ := EID;
  CopyMemory(ErrMsg, PChar(EMsg), Length(EMsg));
end;

procedure SetOption(option: PChar; value: PChar);
begin
  MainForm.SetOption(option, value);
end;

{$ELSE}
function GetVersion: Integer;stdcall; external 'update.dll' name 'GetVersion';
function StartUpdateFiles(info: PUpdateInfo): boolean; stdcall; external 'update.dll' name 'StartUpdateFiles';
procedure StopUpdateFiles; stdcall; external 'update.dll' name 'StopUpdateFiles';
procedure ApplyPatch(patchDir: PChar; plist: PChar; ErrorID:PInteger; ErrMsg: PChar); stdcall; external 'update.dll' name 'ApplyPatch';
procedure SetOption(option: PChar; value: PChar); stdcall;  external 'update.dll' name 'SetOption';
implementation
{$ENDIF}

end.
